<template>
  <div class="list">
    <!-- <div class="list-top">
           <div class="top-content">
               <h3></h3>
           </div>
    </div>-->
    <div class="list-item">
        <div  class="content" v-for="(item ,index) in contentItem" :key="item.id">
          <div @click="intDetail(index,item.id)">
            <div class="imgs">
              <img :src="item.pic" alt />
            </div>
            <span class="names">{{item.name}}</span>
            <p class="text">{{item.characteristic}}</p>
            <p class="price">{{item.minPrice | currency }}</p>
          </div>
          <!-- 可以不用一个div包裹 可以使用.stop阻止事件冒泡@click.stop="addCart(item)  -->
          <!-- <button @click="addCart(item)">加入购物车</button> -->
        </div>
    </div>
  </div>
</template>

<script>
import { currency } from 'utils/filter'
export default {
  props: {
    contentItem: {
      type: Array,
      required: true
    }

  },
  filters: {
    currency
  },
  methods: {
    intDetail (index, id) {
      this.$emit('intDetail', { index, id })
    },
    addCart (item) {
      this.$emit('addCart', item)
    }
  }
}
</script>

<style lang="scss" scoped>
.list {
  width: 100%;
}
.list-item {
  display: flex;
  flex-wrap: wrap;
}
.content {
  width: 50%;
  .imgs {
    img {
      width: 80%;
      display: block;
      margin: 0 auto;
    }
  }
  .names {
    display: block;
    text-align: center;
  }
  .text, .price {
    font-size: 14px;
    color: #666;
    text-align: center;
    padding: 0 20%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-block-start: 2px;
    margin-block-end: 2px;
    margin-inline-start: 2px;
    margin-inline-end: 2px;
  }
  .price {
    color: red;
    line-height: 1;
  }
  button {
    background-color: red;
    border-radius: 5px;
    color: white;
    margin: 0 22% 10px;
  }
}
</style>
